package com.meilele.biz.czh;

import com.meilele.dao.czh.FiveCompanyMapper;
import com.meilele.dao.czh.FiveDesignMapper;
import com.meilele.entity.czh.FiveCompany;
import com.meilele.entity.czh.FiveDesign;
import com.meilele.entity.czh.vo.FiveCDVo;
import com.meilele.entity.czh.vo.FiveComDes;
import com.meilele.util.czh.Constants;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class FiveDesignBiz {
    @Resource
    private FiveDesignMapper fiveDesignMapper;
    @Resource
    private FiveCompanyMapper fiveCompanyMapper;
    public List<FiveDesign> findAll(){
        List<FiveDesign> list=fiveDesignMapper.selectByPrimaryAlla();
        return list;
    }
    public List<FiveDesign> findCity(String designCity,int pageNum){
        int firstPage=(pageNum-1)* Constants.PAGE_SIZE;
        List<FiveDesign> cityList=fiveDesignMapper.selectByPrimaryCity(designCity,firstPage,Constants.PAGE_SIZE);
        return cityList;
    }
    public FiveDesign findId(int designId){
        return fiveDesignMapper.selectByPrimaryKey(designId);
    }
    public FiveCDVo findCompanyId(int designId){
        FiveDesign fiveDesign=fiveDesignMapper.selectByPrimaryId(designId);
        int companyId=fiveDesign.getCompanyId();
        FiveCompany fiveCompany=fiveCompanyMapper.selectByPrimaryKey(companyId);
        FiveCDVo fiveCDVo=new FiveCDVo();
        fiveCDVo.setFiveCompany(fiveCompany);
        fiveCDVo.setFiveDesign(fiveDesign);
        return fiveCDVo;
    }
    public void save(FiveDesign fiveDesign){
        fiveDesignMapper.insert(fiveDesign);
    }

    public int findCount(String designCity){
        return fiveDesignMapper.findCount(designCity);
    }
    public void deleteDesign(int designId){
        fiveDesignMapper.deleteByPrimaryKey(designId);
    }
    public void updateDesign(FiveDesign fiveDesign){
        fiveDesignMapper.updateByPrimaryKey(fiveDesign);
    }
    public int findcont(){
        return fiveDesignMapper.findcont();
    }
   public List<FiveComDes> findCom(int pageNum){
       int firstPage=(pageNum-1)* Constants.PAGE_SIZ;
       List<FiveDesign> list=fiveDesignMapper.selectByPrimaryAll(firstPage,Constants.PAGE_SIZ);
       List<FiveComDes>listCom=new ArrayList<>();
        for (FiveDesign fiveDesign : list){
            int companyId=fiveDesign.getCompanyId();
            FiveCompany fiveCompany=fiveCompanyMapper.selectByPrimaryKey(companyId);
            FiveComDes fiveComDes=new FiveComDes();
            fiveComDes.setCompanyName(fiveCompany.getCompanyName());
            fiveComDes.setDesignName(fiveDesign.getDesignName());
            fiveComDes.setDesignCity(fiveDesign.getDesignCity());
            fiveComDes.setDesignFile(fiveDesign.getDesignFile());
            fiveComDes.setDesignId(fiveDesign.getDesignId());
            fiveComDes.setDesignLogo(fiveDesign.getDesignLogo());
            fiveComDes.setDesignProduce(fiveDesign.getDesignProduce());
            fiveComDes.setDesignSignature(fiveDesign.getDesignSignature());
            listCom.add(fiveComDes);
        }
        return listCom;
   }

}
